layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func', 'tree', 'upload', 'laydate'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var tree = layui.tree;
    var upload = layui.upload;
    var laydate=layui.laydate;

    //渲染时间选择框
    laydate.render({
        elem: "#date",
        tiger: 'click',
        value: new Date().getFullYear(),
        // range: true,
        // type:'month',
        type: 'year'
    });


    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable" ,   //表格id
        condition: {
            deptId: ""
        }
    };
    /**
     * 检索店名
     */
    // var languageAjax = new $ax(Feng.ctxPath + "/btyWage/getDm");
    var languageAjax = new $ax(Feng.ctxPath + "/huopei/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#shopName").append("<option value='" + val.dm + "'>" + val.dm + "</option>");
    });
    form.render('select');

    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {field: 'shopName', align: "center", sort: false, title: '门店名称',width:200},
            {field: 'shopCode', align: "center", sort: false, title: '门店编号',width:100},
            {field: 'turnover', align: "center", sort: false, title: '营业额',width:100},
            {field: 'five', align: "center", sort: false, title: '营业额百分之五'},
            {field: 'ten', align: "center", sort: false, title: '营业额百分之十'},
            {field: 'status', align: "center", sort: false, title: '状态',width:110,templet: function (d) {
                    if (d.status === 1) {
                        return "<p>财务上传</p >";
                    }
                    if (d.status === 2){
                        return "<p>店长审核</p >";
                    }
                    if (d.status === 3){
                        return "<p>财务审核</p >";
                    }
                    if (d.status === 4){
                        return "<p>已推送人事</p >";
                    }
                    if (d.status === 5){
                        return "<p>店长审核不通过</p >";
                    }
                    if (d.status === 6){
                        return "<p>财务审核不通过</p >";
                    }
                    if (d.status === 7){
                        return "<p>已推送店长</p >";
                    }
                }},
            {field: 'ywrq', align: "center", sort: false, title: '业务日期',width:200},
            {field: 'numZongji', align: "center", sort: false, title: '耗用数量分差总计',width:150},
            {field: 'amZongji', align: "center", sort: false, title: '耗用金额分差总计',width:150},
            {field: 'soupSum', align: "center", sort: false, title: '加汤金额总计',width:150},
            // {field: 'className', align: "center", sort: false, title: '品项类别名称'},
            // {field: 'proCode', align: "center", sort: false, title: '品项编号',width:110},
            // {field: 'proName', align: "center", sort: false, title: '品项名称'},
            // {field: 'spec', align: "center", sort: false, title: '规格',width:100},
            // {field: 'unit', align: "center", sort: false, title: '单位',width:80},
            // {field: 'price', align: "center", sort: false, title: '非税单价',width:100},
            // {field: 'thNum', align: "center", sort: false, title: '理论耗用数量'},
            // {field: 'realNum', align: "center", sort: false, title: '实际耗用数量'},
            // {field: 'numTotal', align: "center", sort: false, title: '耗用数量分差'},
            // {field: 'amountTotal', align: "center", sort: false, title: '耗用金额分差'},
            {align: 'center', toolbar: '#tableBar', title: '操作',minWidth:100}
        ]];

    };

    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['shopName'] = $("#shopName").val();
        // queryData['beginTime'] = $("#date").val();
        queryData['timeLimit'] = $("#date").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };


    /**
     * 点击修改
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onEditNotice = function (data) {
        func.open({
            height: 500,
            width:'800px',
            title: '修改银行卡',
            content: Feng.ctxPath + "/alipay/edit?id=" + data.id,
            tableId: Notice.tableId
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/huopei/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        limit: 20,
        cols: Notice.initColumn(),
    });



    /**
     * 导入Excel
     */
    upload.render({
        elem: '#btnExcel'
        , url: '/huopei/import'
        , accept: "file"
        , async: false
        , exts: 'xls|xlsx|xlsm|xlt|xltx|xltm'
        , done: function (res) {
            if (res.state == 0) {
                layer.msg('导入失败！', {icon: 1, time: 2000, shade: 0.2});
            }
            if (res == true) {
                layer.msg('导入成功！', {icon: 1, time: 2000, shade: 0.2});
                window.location.reload();
            }
        },
    });


    // 导出excel
    $('#btnExp').click(function () {
        Notice.exportExcel();
    });

    /**
     * 导出excel按钮
     */
    Notice.exportExcel = function () {
        //选择了门店才可以导出
        var shopName = $("#shopName").val();
        var date = $("#date").val();
        if (shopName == "" || shopName == undefined || shopName == null) {
            Feng.error("请先选择门店");
        } else {
            //获取导出Excel的数据
            var url = Feng.ctxPath + "/huopei/listExport?shopName=" + shopName + "&date=" + date;
            location.href = url;
        }
    };

    /**
     * 投资情况显示
     */
    Notice.costSetting = function (data) {
        window.location.href = Feng.ctxPath + '/huopei/detail?shopCode=' + data.shopCode + "&beginTime=" + data.beginTime;
    };


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });


    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'detail') {
            Notice.costSetting(data);
        }
    });
});
